<?php
session_start(); 
//i : id
//c : code : filename
if(isset($_SESSION['_user'])){
	//defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__)));
	include_once ("mysql.php");
	include_once ("conf.php");
	//die($_GET['id']);
	//$arrCode = explode('-',$_REQUEST["c"]);
	if (isset($_REQUEST["id"]) && intval($_REQUEST["id"])>0 ) {
	    $q	=	mysql_query("SELECT * FROM tailieu WHERE tl_id=".intval($_GET['id']));
	    $num	=	mysql_num_rows($q);
	    $rs	=	mysql_fetch_array($q);
	    if($num == 1) {
	        mysql_query("UPDATE tailieu SET luot_tai=luot_tai+1 WHERE tl_id=".intval($_REQUEST["id"]));
	        //$file=$CONFIG['site_url'].$rs['tl_link'];
	        $doc	=	$_SERVER['DOCUMENT_ROOT'];
	        $file	=	$doc.'/'.$CONFIG['sub_dir'].$rs['tl_link'];
	        //die($file);
	        //echo $file;
	        header("Content-type: application/force-download");
	        header("Content-Transfer-Encoding: Binary");
	        //header("Content-type: application/vnd.ms-word");
	        header("Content-length: ".filesize($file));
	        header("Content-disposition: attachment; filename=\"".$rs['tl_link']."\"");
	        //header("Content-Disposition: attachment; Filename=SaveAsWordDoc.doc");
	        readfile("$file");
	        
	        //die;
	    }
	}else{
	    echo "Loi!";
	}
}
else{
	//header("Location: index.php?act=login");
}
 ?>